<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb>
      <el-breadcrumb-item>成员信息录入</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 表单输入 -->
    <div class="UserFormBox">
      <el-form ref="userFormRef" :model="userForm" :rules="userFormRules" class="SForm_sty">
        <el-form-item prop="userid">
          <el-input v-model="userForm.userid">
            <template slot="prepend">ID</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="pfamily">
           <el-input v-model="userForm.pfamily">
            <template slot="prepend">家族</template>
          </el-input>
        </el-form-item>
       <el-form-item prop="username">
          <el-input v-model="userForm.username">
            <template slot="prepend">姓名</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="birth">
          <el-input v-model="userForm.birth">
            <template slot="prepend">出生日期</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="introduce">
          <el-input v-model="userForm.introduce">
            <template slot="prepend">生平简介</template>
          </el-input>
        </el-form-item>
        <el-form-item prop="death">
          <el-input v-model="userForm.death">
            <template slot="prepend">死亡日期</template>
          </el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button type="primary" @click="inserUser" round>录入</el-button>
          <el-button type="info" @click="resetuserForm" round>重置</el-button>
        </el-form-item>
      </el-form>
      <!-- 提交弹窗 -->
      <el-dialog title="提示" :visible.sync="sucessVisible" width="30%">
        <span>确定录入？</span>
        <span slot="footer" class="dialog-footer">
          <el-button @click="sucessVisible = false">取 消</el-button>
          <el-button type="primary" @click="sucessVisible = false">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      userForm: {
        userid: '',
        username: '',
        birth: '',
        introduce: '',
        death: ''
      },
      // 输入规则
      userFormRules: {
        userid: [
          { required: true, message: '请输入家族ID', trigger: 'blur' }
        ],
        pfamily: [
          { required: true, message: '请输入家族', trigger: 'blur' }
        ],
        username: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        birth: [
          { required: true, message: '请输入出生日期', trigger: 'blur' }
        ],
        introduce: [
          { required: true, message: '请输入生平简介', trigger: 'blur' }
        ],
        death: [
          { required: true, message: '请输入死亡日期', trigger: 'blur' }
        ]

      },
      sucessVisible: false
    }
  },
  methods: {
    // 校验规则
    resetuserForm() {
      this.$refs.userFormRef.resetFields()
    },
    // 提交用户
    inserUser() {
      const { data: res } = this.$http.post('peoples', {
        p_id: this.userForm.userid,
        p_family: this.userForm.pfamily,
        p_name: this.userForm.username,
        p_birth: this.userForm.birth,
        p_introduce: this.userForm.introduce,
        p_death: this.userForm.death
      })
      this.emidtsucess()
      console.log(res)
    },
    // 提交成功提示
    emidtsucess() {
      this.sucessVisible = true
    }
  }
}
</script>

<style lang="less" scoped>
.el-form-item {
  width: 500px;
}

.UserFormBox {
  background-color: #fffffb;
  height: 600px;
  width: 1210px;
  border-radius: 5px;
  margin-left: 10px;
}

.UserForm_sty {
  position: absolute;
  padding: 30px 60px 30px;
  box-sizing: border-box;
}

.btns {
  display: flex;
  justify-content: flex-start;
  margin-top: 60px;
}
</style>
